import { reactive } from "vue";
import type { FormRules } from "element-plus";

/** 广告表单验证规则 */
export const formRules = reactive<FormRules>({
  name: [
    {
      required: true,
      message: "广告名称为必填项",
      trigger: "blur"
    },
    {
      min: 2,
      max: 50,
      message: "广告名称长度应在 2 到 50 个字符之间",
      trigger: "blur"
    }
  ],
  positionId: [
    {
      required: true,
      message: "请选择广告位",
      trigger: "change"
    }
  ],
  type: [
    {
      required: true,
      message: "请选择广告类型",
      trigger: "change"
    }
  ],
  title: [
    {
      max: 100,
      message: "广告标题不能超过 100 个字符",
      trigger: "blur"
    }
  ],
  description: [
    {
      max: 500,
      message: "广告描述不能超过 500 个字符",
      trigger: "blur"
    }
  ],
  imageUrl: [
    {
      type: "url",
      message: "请输入正确的图片链接",
      trigger: "blur"
    }
  ],
  linkUrl: [
    {
      type: "url",
      message: "请输入正确的链接地址",
      trigger: "blur"
    }
  ],
  status: [
    {
      required: true,
      message: "请选择广告状态",
      trigger: "change"
    }
  ],
  startTime: [
    {
      type: "date",
      message: "请选择正确的开始时间",
      trigger: "change"
    }
  ],
  endTime: [
    {
      type: "date",
      message: "请选择正确的结束时间",
      trigger: "change"
    }
  ],
  sort: [
    {
      required: true,
      message: "排序值为必填项",
      trigger: "blur"
    },
    {
      type: "number",
      min: 0,
      max: 9999,
      message: "排序值应在 0 到 9999 之间",
      trigger: "blur"
    }
  ],
  advertiser: [
    {
      max: 100,
      message: "广告主不能超过 100 个字符",
      trigger: "blur"
    }
  ],
  budget: [
    {
      type: "number",
      min: 0,
      message: "投放预算不能小于 0",
      trigger: "blur"
    }
  ],
  remark: [
    {
      max: 500,
      message: "备注不能超过 500 个字符",
      trigger: "blur"
    }
  ]
});

/** 广告位表单验证规则 */
export const positionFormRules = reactive<FormRules>({
  name: [
    {
      required: true,
      message: "广告位名称为必填项",
      trigger: "blur"
    },
    {
      min: 2,
      max: 50,
      message: "广告位名称长度应在 2 到 50 个字符之间",
      trigger: "blur"
    }
  ],
  code: [
    {
      required: true,
      message: "广告位编码为必填项",
      trigger: "blur"
    },
    {
      pattern: /^[a-zA-Z0-9_-]+$/,
      message: "广告位编码只能包含字母、数字、下划线和横线",
      trigger: "blur"
    },
    {
      min: 2,
      max: 30,
      message: "广告位编码长度应在 2 到 30 个字符之间",
      trigger: "blur"
    }
  ],
  type: [
    {
      required: true,
      message: "请选择广告位类型",
      trigger: "change"
    }
  ],
  description: [
    {
      max: 500,
      message: "广告位描述不能超过 500 个字符",
      trigger: "blur"
    }
  ],
  width: [
    {
      type: "number",
      min: 1,
      max: 9999,
      message: "宽度应在 1 到 9999 之间",
      trigger: "blur"
    }
  ],
  height: [
    {
      type: "number",
      min: 1,
      max: 9999,
      message: "高度应在 1 到 9999 之间",
      trigger: "blur"
    }
  ],
  status: [
    {
      required: true,
      message: "请选择广告位状态",
      trigger: "change"
    }
  ],
  pageLocation: [
    {
      max: 100,
      message: "页面位置不能超过 100 个字符",
      trigger: "blur"
    }
  ],
  sort: [
    {
      required: true,
      message: "排序值为必填项",
      trigger: "blur"
    },
    {
      type: "number",
      min: 0,
      max: 9999,
      message: "排序值应在 0 到 9999 之间",
      trigger: "blur"
    }
  ],
  remark: [
    {
      max: 500,
      message: "备注不能超过 500 个字符",
      trigger: "blur"
    }
  ]
});

/** 搜索表单验证规则 */
export const searchFormRules = reactive<FormRules>({
  name: [
    {
      max: 50,
      message: "名称不能超过 50 个字符",
      trigger: "blur"
    }
  ],
  advertiser: [
    {
      max: 100,
      message: "广告主不能超过 100 个字符",
      trigger: "blur"
    }
  ]
});